<template>
  <div>
    <el-form-item label="计算公式">
      <el-input
        v-model="activeData.calcFormula"
        placeholder="计算公式"
        readonly
        @click.native="handleOpenFormulaDialog"
      />
    </el-form-item>
    <input-config :active-data="activeData" />
    <formula-dialog
      ref="formulaDialog"
      :fields="fields"
      @save="handleChangeFormula"
      :cm-value="activeData.calcFormula"
    />
  </div>
</template>

<script>
import InputConfig from './input'
import FormulaDialog from '../../formula/index'
import mixin from './mixin'

export default {
  name: 'ConfigItemFunctionCalc',
  mixins: [mixin],
  props: ['fields'],
  components: {
    InputConfig,
    FormulaDialog
  },
  data() {
    return {
      filterFields: []
    }
  },
  methods: {
    // 过滤能用于函数计算的字段
    handleFilterFields() {
      // let list = ["INPUT","NUMBER"]
      this.filterFields = this.fields.filter((item) => {
        return list.includes(item.typeId)
      })
    },
    handleOpenFormulaDialog() {
      this.$refs.formulaDialog.open()
    },
    handleChangeFormula(val) {
      this.$set(this.activeData, 'calcFormula', val)
    }
  }
}
</script>

<style scoped></style>
